package com.moxiao.yfjh.module.maker.controller.app;

import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.module.maker.controller.admin.makerProductInfo.vo.MatchmakerProductInfoPageReqVO;
import com.moxiao.yfjh.module.maker.controller.admin.makerProductInfo.vo.MatchmakerProductInfoRespVO;
import com.moxiao.yfjh.module.maker.convert.makerProductInfo.MatchmakerProductInfoConvert;
import com.moxiao.yfjh.module.maker.dal.dataobject.makerProductInfo.MatchmakerProductInfoDO;
import com.moxiao.yfjh.module.maker.service.makerProductInfo.MatchmakerProductInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Objects;

import static com.moxiao.yfjh.framework.common.pojo.CommonResult.success;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2024/2/29 13:55
 **/

@Tag(name = "App - 红娘商品信息")
@RestController
@RequestMapping("/maker/matchmaker-product-info")
@Validated
public class AppMakerProductController {

    @Resource
    private MatchmakerProductInfoService matchmakerProductInfoService;

    @GetMapping("/getMatchmakerProductInfoPage")
    @Operation(summary = "获得相亲红娘商品信息分页")
    public CommonResult<PageResult<MatchmakerProductInfoRespVO>> getMatchmakerProductInfoPage(@Valid MatchmakerProductInfoPageReqVO pageVO) {
        PageResult<MatchmakerProductInfoDO> pageResult = matchmakerProductInfoService.getMatchmakerProductInfoPage(pageVO);
        return success(MatchmakerProductInfoConvert.INSTANCE.convertPage(pageResult));
    }


    @GetMapping("/getMatchmakerProductInfo")
    @Operation(summary = "获得相亲红娘商品信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<MatchmakerProductInfoRespVO> getMatchmakerProductInfo(@RequestParam("id") Long id) {
        MatchmakerProductInfoDO matchmakerProductInfo = matchmakerProductInfoService.getMatchmakerProductInfo(id);
        MatchmakerProductInfoRespVO vo = MatchmakerProductInfoConvert.INSTANCE.convert(matchmakerProductInfo);
        if (Objects.nonNull(vo)) {
            vo.setSalesVolume(matchmakerProductInfoService.getMakerSalesVolume(vo.getId()));
        }
        return success(vo);
    }

}
